/**
 * Created by Jack Xue on 20101024
 */
package org.code.jack.jweberp.service.impl;

import java.util.Date;
import java.util.List;

import org.code.jack.jweberp.dao.IUserDao;
import org.code.jack.jweberp.domain.User;
import org.code.jack.jweberp.service.IUserService;
import org.code.jack.jweberp.utils.Encrypt;

public class UserServiceBean extends CrudServiceBean<User, IUserDao> implements IUserService {

	@Override
	public User login(String userName, String password, String ip) {
		IUserDao userDaoBean = getGenericDao();
		User user = userDaoBean.getEntityByField("userName", userName, "=");
		if(user != null && user.getPassword().equals(Encrypt.MD5Encode(password)) && user.getStatus() > 0){
			user.setLoginTimes(user.getLoginTimes()+1);
			user.setLastLoginTime(new Date());
			user.setLastLoginIP(ip);
			this.updateEntity(user);
			return user;
		}
		return null;
	}

	@Override
	public List<User> getEntityList() {
		// TODO Auto-generated method stub
		return null;
	}
}
